/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import javax.faces.context.FacesContext;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "candidate_type")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CandidateType.findAll", query = "SELECT c FROM CandidateType c"),
    @NamedQuery(name = "CandidateType.findByIdCandidateType", query = "SELECT c FROM CandidateType c WHERE c.idCandidateType = :idCandidateType"),
    @NamedQuery(name = "CandidateType.findByDescription", query = "SELECT c FROM CandidateType c WHERE c.description = :description")})
public class CandidateType implements Serializable,InternationalizableEntity {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_CANDIDATE_TYPE")
    private Integer idCandidateType;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "candidateType", fetch = FetchType.LAZY)
    private List<CandidateTypeDescription> candidateTypeDescriptionList;
    @OneToMany(mappedBy = "candidateType", fetch = FetchType.LAZY)
    private List<Candidate> candidateList;

    public CandidateType() {
    }

    public CandidateType(Integer idCandidateType) {
        this.idCandidateType = idCandidateType;
    }

    public CandidateType(Integer idCandidateType, String description) {
        this.idCandidateType = idCandidateType;
        this.description = description;
    }

    public Integer getIdCandidateType() {
        return idCandidateType;
    }

    public void setIdCandidateType(Integer idCandidateType) {
        this.idCandidateType = idCandidateType;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getCandidateTypeDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(CandidateTypeDescription cd:getCandidateTypeDescriptionList()){
//                if(cd.getLanguage().getCode().equals(localeCode)){
//                    resDescription=cd.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlTransient
    public List<CandidateTypeDescription> getCandidateTypeDescriptionList() {
        return candidateTypeDescriptionList;
    }

    public void setCandidateTypeDescriptionList(List<CandidateTypeDescription> candidateTypeDescriptionList) {
        this.candidateTypeDescriptionList = candidateTypeDescriptionList;
    }

    @XmlTransient
    public List<Candidate> getCandidateList() {
        return candidateList;
    }

    public void setCandidateList(List<Candidate> candidateList) {
        this.candidateList = candidateList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCandidateType != null ? idCandidateType.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CandidateType)) {
            return false;
        }
        CandidateType other = (CandidateType) object;
        if ((this.idCandidateType == null && other.idCandidateType != null) || (this.idCandidateType != null && !this.idCandidateType.equals(other.idCandidateType))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.CandidateType[ idCandidateType=" + idCandidateType + " ]";
    }

    @Override
    public Integer getId() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getCandidateTypeDescriptionList();
    }
    
}
